package com.seek.edustatistics.controller;


import com.seek.commonutils.ResponseResult;
import com.seek.edustatistics.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author wml
 * @since 2022-03-05
 */
@RestController
@RequestMapping("/edustatistics/statistics")
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    // 统计某一天注册人数，生成统计数据
    @PostMapping("countRegister/{date}")
    public ResponseResult countRegister(@PathVariable String date) {
        statisticsDailyService.countRegister(date);
        return ResponseResult.ok();
    }

    // 图表显示，返回两部分数据，日期、数量的 json 数组
    @GetMapping("showData/{type}/{begin}/{end}")
    public ResponseResult showData(@PathVariable String type,
                                   @PathVariable String begin, @PathVariable String end) {
        System.out.println("===========================" + type);
        System.out.println("===========================" + begin);
        System.out.println("===========================" + end);
        Map<String, Object> map = statisticsDailyService.showData(type, begin, end);
        return ResponseResult.ok().data(map);
    }

    // 统计一个月以内注册的人数，按天数统计
    @GetMapping("getRegistryMonth")
    public ResponseResult getRegistryMonth() {
        Map<String, Object> map = statisticsDailyService.getRegistryMonth();
        return ResponseResult.ok().data(map);
    }

    // 统计一年内注册的人数，按月数统计
    @GetMapping("getRegistryYear")
    public ResponseResult getRegistryYear() {
        Map<String, Object> map = statisticsDailyService.getRegistryYear();
        return ResponseResult.ok().data(map);
    }

    // 根据浏览量降序查询十条数据
    @GetMapping("getPopularCourse")
    public ResponseResult getPopularCourse() {
        Map<String, Object> map = statisticsDailyService.getPopularCourse();
        return ResponseResult.ok().data(map);
    }

}

